Step 40: Deploy
Let's deploy the Bookmark API to Heroku.
-
Head over to Heroku and create a new app. I called my app
bookmark-api-fsjs
. -
In Settings, Add "Nodejs" as a "Buildpack."
-
In Settings, click on Reveal “Config Vars” and add
DB_URL
(with its value for your app that points to the MongoDB cluster you’ve created in the cloud.) Note you should not wrap the connection URI in double quotations. You may also want to change the database name to something like “prod” (for production). -
Update
const ****PORT = 3000;
inserver.js
toconst PORT = process.env.PORT || 3000;
-
Add a
Procfile
to the project root folder:web: yarn start
-
Next, create a
.github
folder. Add a subfolderworkflows
to.github
. Finally, add adeploy.yml
file to this subfolder with the following content:name: Deploy the server (backend) app on: push: branches: - main jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: akhileshns/heroku-deploy@v3.12.12 with: heroku_api_key: ${{secrets.HEROKU_AUTH_TOKEN}} heroku_app_name: ${{secrets.HEROKU_APP_NAME}} heroku_email: ${{secrets.HEROKU_AUTH_EMAIL}}
-
Create a GitHub repository for this project. Go to the GitHub repository for this project and select the “Settings” tab. Then, under the “Security” heading, open “Secrets” and select “Actions.” Finally, add the secrets that your
deploy.yml
depends on. -
Push your code to the GitHub repository and watch GitHub Action deploy your app to Heroku!